package com.valiscalc.util.statistics;

import cn.hutool.core.math.MathUtil;
import com.valiscalc.entity.SuperLotto;

import java.util.ArrayList;
import java.util.List;

/**
 * @Classname CalcLotteryUtil
 * @Description 此类用于计算彩票的基本算法
 * @Date 2020/11/18 18:32
 * @Created by vallis
 */
public class CalcLotteryUtil {
    
    
    /**
     * 将输入的 int数组 转换成 String类型
     */
    public static String[] intArrayToString(int[] checkNumber) {
        
        String[] checkNumberByStr = new String[checkNumber.length];
        for (int i = 0; i < checkNumber.length; i++) {
            checkNumberByStr[i] = String.valueOf(checkNumber[i]);
            
        }
        return checkNumberByStr;
        
    }
    
    /**
     * 将输入的 String数组 转换成 int类型
     *
     * @param checkNumber
     *
     * @return
     */
    public static int[] stringArrayToInt(String[] checkNumber) {
        int[] checkNumberByInt = new int[checkNumber.length];
        for (int i = 0; i < checkNumber.length; i++) {
            checkNumberByInt[i] = Integer.parseInt(checkNumber[i]);
            
        }
        return checkNumberByInt;
    }
    
    /**
     * 将String 转换成String数组
     *
     * @param string
     *
     * @return
     */
    public static String[] changeToArray(String string) {
        return string.split(",");
    }
    
    
    /**
     * 生成所有可能的5+0组合
     *
     * @return
     */
    public static List<String[]> bornAllFrontNum() {
        int[] all = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35};
        
        return MathUtil.combinationSelect(intArrayToString(all), 5);
    }
    
    /**
     * 将此大乐透彩票拆解成标准的5+2形式
     *
     * @param superLotto
     *
     * @return
     */
    public static List<LottoTicket> decomposed(SuperLotto superLotto) {
        List<String[]> allFist = MathUtil.combinationSelect(changeToArray(superLotto.getFrontNum()), 5);
        List<String[]> allBack = MathUtil.combinationSelect(changeToArray(superLotto.getEndNum()), 2);
        List<LottoTicket> tickets = new ArrayList<>();
        LottoTicket lottoTicket = null;
        for (String[] first : allFist) {
            for (String[] back : allBack) {
                lottoTicket = new LottoTicket(first, back);
                
                tickets.add(lottoTicket);
            }
        }
        return tickets;
    }
    
    public static void main(String[] args) {
        SuperLotto superLotto = new SuperLotto();
        superLotto.setFrontNum("1,2,3,4,5");
        superLotto.setEndNum("2,3,4");
        List<LottoTicket> decomposed = decomposed(superLotto);
        decomposed.forEach(System.out::println);
    }
}
